<?php
namespace app\decorate\controller;
use app\AdminRest;
use app\decorate\model\Customer;
use app\decorate\model\Scheme;
use think\App;
use think\Request;
use app\decorate\model\AdminOfferRecord as offer_model;

class AdminOfferRecord extends AdminRest{
    protected $model;
    public function __construct(App $app) {
        parent::__construct($app);
        $this->model = new offer_model();
    }
    /**
     * User: chenniang
     * Date: 2019-10-09 15:58
     * @return \think\Response
     * descption:评论报价记录
     */
    public function offerList(){
        $input = $this->_param;
        $where = [];
        if(!empty($input['name'])){
            $where[] = ['b.nickName','like',"%\\".$input['name']."%"];
            $where[] = ['a.area','like',"%\\".$input['name']."%"];
            $where[] = ['a.mobile','like',"%\\".$input['name']."%"];
        }
        if(!empty($input['staff_id'])){
            $dis[] = ['a.staff_id','=',$input['staff_id']];
        }
        $dis[] = ['a.uniacid','=',$this->_uniacid];
        $dis[] = ['a.status','>',-1];
        $data  = $this->model->offerList($dis,$input['limit'],$where);
        return $this->success($data);
    }
    /**
     * User: chenniang
     * Date: 2019-10-09 15:59
     * @return \think\Response
     * descption:编辑|回显报价记录
     */
    public function offerUpdate(){
        $input = $this->_input;
        if(count($input)>1){
            $data = $this->model->offerUpdate(['id'=>$input['id']],$input);
        }else{
            $data = $this->model->offerInfo(['id'=>$input['id']]);
        }
        return $this->success($data);
    }


    /**
     * @author chenniang
     * @DataTime: 2020-11-19 11:11
     * @功能说明:客服列表
     */
    public function customerList(){

        $input = $this->_input;

        $dis = [

            'uniacid' => $this->_uniacid
        ];

        $where = [];

        if(!empty($input['name'])){

            $where[] = ['user_name','like','%'.$input['name'].'%'];

            $where[] = ['wx','like','%'.$input['name'].'%'];

            $where[] = ['mobile','like','%'.$input['name'].'%'];
        }

        $customer_model = new Customer();

        $data = $customer_model->dataList($dis,$where,$input['limit']);

        return $this->success($data);

    }


    /**
     * @author chenniang
     * @DataTime: 2020-11-19 11:19
     * @功能说明:添加客服
     */
    public function customerAdd(){

        $input = $this->_input;

        $customer_model = new Customer();

        $input['uniacid'] = $this->_uniacid;

        $res  = $customer_model->dataAdd($input);

        return $this->success($res);

    }


    /**
     * @author chenniang
     * @DataTime: 2020-11-19 11:19
     * @功能说明:添加客服
     */
    public function customerUpdate(){

        $input = $this->_input;

        $customer_model = new Customer();

        $input['uniacid'] = $this->_uniacid;

        $res  = $customer_model->dataUpdate(['id'=>$input['id']],$input);

        return $this->success($res);

    }


    /**
     * @author chenniang
     * @DataTime: 2020-11-19 15:00
     * @功能说明:获取客户的列表
     */
    public function schemeList(){

        $input = $this->_input;

        $scheme_model = new Scheme();

        $dis[] = ['a.uniacid','=',$this->_uniacid];

        $where = [];

        if(!empty($input['name'])){

            $where[] = ['b.nickName','like','%'.$input['name'].'%'];

            $where[] = ['a.mobile','like','%'.$input['name'].'%'];
        }

        if(!empty($input['staff_id'])){

            $dis[] = ['a.staff_id','=',$input['staff_id']];
        }

        $res = $scheme_model->dataList($dis,$where,$input['limit']);

        return $this->success($res);

    }




}
